package org.nf.trading.service.app.address.impl;


import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.nf.trading.dao.AddressMapper;
import org.nf.trading.entity.Address;
import org.nf.trading.exception.app.address.AddressDataException;
import org.nf.trading.service.app.address.AddressService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Slf4j
@RequiredArgsConstructor
@Transactional
public class AddressServiceImpl implements AddressService {
    private final AddressMapper addressMapper;

    /**
     * 添加地址
     * @param address
     * @return
     */
    @Override
    public boolean insert(Address address) {
        if (address == null){
            throw new AddressDataException(500,"数据为空");
        }
        int insert = addressMapper.insert(address);
        return insert == 1;
    }

    /**
     * 通过用户id查询全部地址
     * @param uid
     * @return
     */
    @Override
    public List<Address> listAddressByUid(Integer uid) {
        if (uid == null){
            log.error("参数为空");
            throw new AddressDataException(500,"参数为空");
        }
        return addressMapper.listAddressByUid(uid);
    }

    /**
     * 通过id查询地址信息
     * @param addressId
     * @return
     */
    @Override
    public Address selectByPrimaryKey(Integer addressId) {
        if (addressId == null){
            log.error("参数异常");
            throw new AddressDataException(500,"参数异常");
        }
        return addressMapper.selectByPrimaryKey(addressId);
    }
}
